/**
 * Copyright 2011 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.api.adwords.starterkit.db.structures;

import org.apache.commons.lang.ArrayUtils;
import org.apache.log4j.Logger;

import com.google.api.adwords.starterkit.utils.Utils;
import com.google.api.adwords.v201101.cm.AdGroupAdStatus;

/**
 * The Class TextAdStructure represents all TextAd fields managed by 
 * StarterKit.
 * 
 * @author rodrigo.f.vale@gmail.com  (Rodrigo Vale)
 */
public class TextAdStructure {
  private int localId;
  private long creativeId;
  public int localAdGroupId;
  private long adGroupId;
  private String headline;
  private String description1;
  private String description2;
  private String displayUrl;
  private String destinationUrl;
  private boolean isStatsAvailable;
  private AdGroupAdStatus status;

  private float ctr;
  private long clicks;
  private float cost;
  private long impressions;
  private long conversions;
  private long transactions;

  private boolean isStatusModifiable;
  private boolean banned;
  
  private static final Logger log = Logger.getLogger("StarterKit");
  
  public void setLocalId(int localId) {
    this.localId = localId;
  }
  
  public int getLocalId() {
    return localId;
  }
  
  public void setCreativeId(long creativeId) {
    this.creativeId = creativeId;
  }
  
  public long getCreativeId() {
    return creativeId;
  }

  public void setAdGroupId(long adGroupId) {
    this.adGroupId = adGroupId;
  }

  public long getAdGroupId() {
    return adGroupId;
  }

  public void setHeadline(String headline) {
    this.headline = headline;
  }

  public String getHeadline() {
    return headline;
  }

  public void setDescription1(String description1) {
    this.description1 = description1;
  }

  public String getDescription1() {
    return description1;
  }

  public void setDescription2(String description2) {
    this.description2 = description2;
  }

  public String getDescription2() {
    return description2;
  }

  public void setDisplayUrl(String displayUrl) {
    this.displayUrl = displayUrl;
  }

  public String getDisplayUrl() {
    return displayUrl;
  }

  public void setDestinationUrl(String destinationUrl) {
    this.destinationUrl = destinationUrl;
  }

  public String getDestinationUrl() {
    return destinationUrl;
  }

  public void setStatsAvailable(boolean isStatsAvailable) {
    this.isStatsAvailable = isStatsAvailable;
  }

  public boolean isStatsAvailable() {
    return isStatsAvailable;
  }

  public void setStatus(AdGroupAdStatus status) {
    this.status = status;
  }

  public void setStatus(String status) {
    status = status.toUpperCase();
    validateStatus(status);
    this.status = AdGroupAdStatus.fromString(status);
  }
  
  public AdGroupAdStatus getStatus() {
    return status;
  }

  public void setCtr(float ctr) {
    this.ctr = ctr;
  }

  public float getCtr() {
    return ctr;
  }

  public void setClicks(long clicks) {
    this.clicks = clicks;
  }

  public long getClicks() {
    return clicks;
  }

  public void setCost(float cost) {
    this.cost = cost;
  }

  public float getCost() {
    return cost;
  }

  public void setImpressions(long impressions) {
    this.impressions = impressions;
  }

  public long getImpressions() {
    return impressions;
  }

  public void setConversions(long conversions) {
    this.conversions = conversions;
  }

  public long getConversions() {
    return conversions;
  }

  public void setTransactions(long transactions) {
    this.transactions = transactions;
  }

  public long getTransactions() {
    return transactions;
  }

  public void setStatusModifiable(boolean isStatusModifiable) {
    this.isStatusModifiable = isStatusModifiable;
  }

  public boolean getCanModifyStatus() {
    return isStatusModifiable;
  }

  public void setBanned(boolean banned) {
    this.banned = banned;
  }

  public boolean isBanned() {
    return banned;
  }  
  
  public static boolean validateStatus(String status) {
    String valids[] = {"DISABLED", "ENABLED", "PAUSED"};
    if (!ArrayUtils.contains(valids, status)) {
      log.error("Wrong TextAd status:" + status);
      log.error("Valids status are: " + Utils.toString(valids));
      throw new RuntimeException();
    }
    return true;
  }   
}